route.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import { NextRequest, NextResponse } from 'next/server';
  2. import { ResultDto } from '@/types/response/common';
  3. import { fetchJson } from '@/lib/utils/server';
  4. // /api/posts/{id}/prediction, /api/posts/{id}/cheers 등 (백엔드 posts 루트 — forum/posts 와 별개)
  5. export async function GET(request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  6. const { path } = await params;
  7. const endpoint = `/api/posts/${path.join('/')}`;
  8. const url = new URL(request.url);
  9. const res: ResultDto = await fetchJson(`${endpoint}${url.search}`, { method: 'GET' });
  10. return NextResponse.json(res);
  11. }
  12. // D3 응원 발신 — POST /api/posts/{postID}/cheers { amount, message? }
  13. export async function POST(request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
  14. const { path } = await params;
  15. const endpoint = `/api/posts/${path.join('/')}`;
  16. const contentType = request.headers.get('content-type') || '';
  17. const raw = await request.arrayBuffer();
  18. if (raw.byteLength > 0) {
  19. const res: ResultDto = await fetchJson(endpoint, {
  20. method: 'POST',
  21. body: raw,
  22. headers: contentType ? { 'Content-Type': contentType } : undefined
  23. });
  24. return NextResponse.json(res);
  25. }
  26. const res: ResultDto = await fetchJson(endpoint, { method: 'POST' });
  27. return NextResponse.json(res);
  28. }